<style type="text/css">
    .layui-table-body{overflow-x:auto;}
    .layui-table-cell{font-size:12px;}
</style>

<table id="dataTable"></table>
<script type="text/html" id="goodsTpl">
    <div style="line-height:18px;">
    <img src="{{ d.pic ? d.pic : '__ADMIN_IMG__/avatar.png' }}" width="60" height="60" class="fl">
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('banner_edit')}?type=2&id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '1000px', height: '500px', title: '修改Banner'}">修改</a><a href="{:url('banner_del')}?type=2&id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>
{include file="system@block/layui" /}
<script id="toolbar" type="text/html">
    <a href="{:url('banner_add')}?type=2" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe-pop" hisi-data="{width: '1000px', height: '500px', title: '添加Banner'}">&nbsp;添加</a>
    <!-- <a href="{:url('index_export')}" class="layui-btn layui-btn-primary layui-icon layui-icon-play" width="460" height="270">&nbsp;导出</a> -->
    <!-- <button type="button" class="layui-btn" id="test1">
        <i class="layui-icon">&#xe67c;</i>导入excel
      </button> -->
</script>
<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {field: 'id', title: 'ID'}
                ,{title: 'Banner图', templet: '#goodsTpl'}
                ,{field: 'link', title: '链接'}
                ,{field: 'status', title: '状态'}
                ,{field: 'ctime', title: '更新时间',templet : "<div>{{layui.util.toDateString(d.ctime, 'yyyy年-MM月-dd日 HH:mm:ss')}}</div>"}
                ,{field: 'orders', title: '排序'}
                ,{title: '操作', width: 120, templet: '#buttonTpl'}
            ]]
            ,done: function(){
                if (typeof(layui.global.addTableTool) !== 'undefined') {
                    layui.global.addTableTool();
                }
            }
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload; //得到 upload 对象
        //创建一个上传组件
        upload.render({
        elem: '#test1'
        ,url: '{:url("goods_import")}'
        ,method:'post'
        ,done: function(res){ //上传后的回调
            // console.log(res);
            if(res.status=='success'){
                layer.msg('导入成功');
                window.location.reload();
            }
            else{
                layer.msg(res.msg);
            }
        } 
        ,accept: 'file' //允许上传的文件类型
        //,size: 50 //最大允许上传的文件大小
        //,……
        })
    });
</script>